package com.ck.list;

import com.ck.list.entity.ClassEntity;
import com.ck.list.entity.StudentEntity;
import org.apache.commons.compress.utils.Lists;
import org.apache.commons.compress.utils.Sets;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class ListDemo2 {

    static List<ClassEntity> classList = Lists.newArrayList();
    static Map<String, Object> studentMap = new HashMap<>();

    public static void main(String[] args) {
        initStudentListData();
        initClassData();
        Set<ClassEntity> classEntitySet = Sets.newHashSet();
        classList.forEach(c -> {
            List<StudentEntity> studentEntityList = (List<StudentEntity>) studentMap.get(c.getId());
            if(studentEntityList == null) {
                classEntitySet.add(c);
            }
            c.setStudentList(studentEntityList);
        });
        //classEntitySet.forEach(c -> classList.remove(c));

        System.out.println(classList);
        System.out.println("----------------------------");
        System.out.println(studentMap);
    }

    private static void initStudentListData(){
        List<StudentEntity> studentList;
        StudentEntity studentEntity;
        for (int i = 0; i < 5; i++) {
            studentEntity = new StudentEntity();
            studentList = Lists.newArrayList();
            studentEntity.setStudentName("张三"+i);
            studentEntity.setAge(18);
            studentEntity.setClassId((i+1)+"");
            studentEntity.setSex("男");
            studentEntity.setId(i+"");
            studentList.add(studentEntity);
            studentMap.put((i + 1) + "", studentList);
        }
    }

    private static void initClassData() {
        ClassEntity classEntity;
        for (int i = 0; i < 6; i++) {
            classEntity = new ClassEntity();
            classEntity.setClassCode(100+i);
            classEntity.setClassName("红星"+(i+1)+"班");
            classEntity.setId((i+1)+"");
            classList.add(classEntity);
        }
    }
}
